Dockerizing a CSharp
So, A simple dockerfile would look something like this
FROM mcr.microsoft.com/dotnet/sdk:7.0
COPY . /app
WORKDIR /app
RUN \["dotnet", "restore"\]
RUN \["dotnet", "build"\]
ENTRYPOINT \["dotnet", "run"\]
Our base image is mcr.microsoft.com/dotnet/sdk:7.0
, which is the dotNet SDK.
Next we cope everything and put it into /app.
here's what the project folder structure looks like:
|-modulescmds
|-Program.cs
|-dockerfile
|-project.csproj
Afterward we set the work directory to /app (any command eg: the next line, will be run in this folder)
Next we run dotnet restore
& dotnet run
Finally entrypoint is an alternative to the typical CMD, the differences are explained in this doc: https://www.docker.com/blog/docker-best-practices-choosing-between-run-cmd-and-entrypoint/
Finally we can build and run it like so
docker build -t imagename .
docker run imagename